﻿using Microsoft.Extensions.ObjectPool;
using RabbitMQChannel = RabbitMQ.Client.IModel;
using RabbitMQConnection = RabbitMQ.Client.IConnection;

namespace WAU.Library.RabbitMQ
{
    /// <summary>
    /// RabbitMQChannel 的包装类
    /// </summary>
    public class RabbitMQModelLease
    {
        /// <summary>
        /// 全局池对象
        /// </summary>
        private ObjectPool<RabbitMQChannel> _pool;

        /// <summary>
        /// Channel
        /// </summary>
        public RabbitMQChannel Channel;

        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="pool"></param>
        public RabbitMQModelLease(ObjectPool<RabbitMQChannel> pool)
        {
            _pool = pool;
            Channel = pool.Get();
        }

        /// <summary>
        /// Release
        /// </summary>
        public void Release()
        {
            _pool.Return(Channel);
        }
    }
}
